package com.ruoyi.security.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.InspectionRecord;
import com.ruoyi.security.domain.vo.InRecordResult;
import com.ruoyi.security.service.IInspectionRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 巡更记录Controller
 *
 * @author cjie
 * @date 2022-04-14
 */
@Api(tags = " 巡更记录")
@RestController
@RequestMapping("/inspectionRecord")
public class InspectionRecordController extends BaseController {
    @Autowired
    private IInspectionRecordService inspectionRecordService;

    /**
     * 查询巡更记录列表
     */
    @ApiOperation(value="查询巡更记录列表", notes="查询巡更记录列表")
    @PreAuthorize(hasPermi = "security:inspectionRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(InspectionRecord inspectionRecord) {
        startPage();
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡更记录列表
     */
    @ApiOperation(value="导出巡更记录列表", notes="导出巡更记录列表")
    @PreAuthorize(hasPermi = "security:inspectionRecord:export")
    @Log(title = "巡更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionRecord inspectionRecord) throws IOException {
        List<InspectionRecord> list = inspectionRecordService.selectInspectionRecordList(inspectionRecord);
        ExcelUtil<InspectionRecord> util = new ExcelUtil<InspectionRecord>(InspectionRecord.class);
        util.exportExcel(response, list, "巡更记录数据");
    }
    /**
     * 获取巡更记录详细信息
     */
    @ApiOperation(value="获取巡更记录详细信息", notes="获取巡更记录详细信息")
    @PreAuthorize(hasPermi = "security:inspectionRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(inspectionRecordService.selectInspectionRecordById(id));
    }

    /**
     * 新增巡更记录
     */
    @ApiOperation(value="新增巡更记录", notes="新增巡更记录")
    @PreAuthorize(hasPermi = "security:inspectionRecord:add")
    @Log(title = "巡更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.insertInspectionRecord(inspectionRecord));
    }

    /**
     * 新增巡更记录
     */
    @ApiOperation(value="微信新增巡更记录", notes="微信新增巡更记录")
    @PreAuthorize(hasPermi = "security:inspectionRecord:add")
    @Log(title = "微信巡更记录", businessType = BusinessType.INSERT)
    @PostMapping("/wx/add")
    public AjaxResult addInfo(@RequestBody InspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.insertWXInspectionRecord(inspectionRecord));
    }

    /**
     * 获取巡更记录详细信息
     */
    @ApiOperation(value="微信获取记录详情", notes="微信获取记录详情")
    @PreAuthorize(hasPermi = "security:inspectionRecord:query")
    @GetMapping(value = "/wx/{id}")
    public AjaxResult getWXInfo(@PathVariable("id") String id) {
        return AjaxResult.success(inspectionRecordService.selectWXInspectionRecordById(id));
    }

    @ApiOperation(value="微信获取统计结果", notes="微信获取统计结果")
    @PreAuthorize(hasPermi = "security:inspectionRecord:list")
    @GetMapping("/wx/computeCard")
    public AjaxResult computeCard(InspectionRecord inspectionRecord) {
        Map<String, InRecordResult> map = inspectionRecordService.computeCard(inspectionRecord);
        return AjaxResult.success(map);
    }

    /**
     * 修改巡更记录
     */
    @ApiOperation(value="修改巡更记录", notes="修改巡更记录")
    @PreAuthorize(hasPermi = "security:inspectionRecord:edit")
    @Log(title = "巡更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.updateInspectionRecord(inspectionRecord));
    }

    @ApiOperation(value="微信修改巡更记录", notes="微信修改巡更记录")
    @PreAuthorize(hasPermi = "security:inspectionRecord:edit")
    @Log(title = "巡更记录", businessType = BusinessType.UPDATE)
    @PutMapping("/wx/edit")
    public AjaxResult editWXInfo(@RequestBody InspectionRecord inspectionRecord) {
        return toAjax(inspectionRecordService.updateWXInspectionRecord(inspectionRecord));
    }
    /**
     * 删除巡更记录
     */
    @ApiOperation(value="删除巡更记录", notes="删除巡更记录")
    @ApiImplicitParam(name = "ids", value = "巡更记录ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:inspectionRecord:remove")
    @Log(title = "巡更记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(inspectionRecordService.deleteInspectionRecordByIds(ids));
    }

}
